var express = require('express');
var router = express.Router();
var { billModel } = require('../../../model/model')
/* GET home page. */



// 获取财务信息
router.get('/getbill', async (req, res) => {
  let user = req.query.data;
  console.log(user);
  let arr = []
  if (user != undefined) {
    if (user.from._id != '') {
      arr.push({ _id: user.from._id })
    }
    if (user.from.state != '请选择订单状态') {
      arr.push({ state: user.from.state })
    }
    if (user.from.goodsid != '') {
      arr.push({ goodsid: user.from.goodsid })
    }
    if (user.from.After_sales_managementid != '') {
      arr.push({After_sales_managementid: user.from.After_sales_managementid })
    }
    console.log(arr);
    if (arr.length > 0) {
      let data = await billModel.find({$and:arr}).populate('After_sales_managementid').populate('goodsid').populate('groupsid')
      console.log(data);
      res.send({
        code: 200,
        msg: '获取成功',
        data
      })
    } else {
      let data = await billModel.find().populate('After_sales_managementid').populate('goodsid').populate('groupsid')
      res.send({
        code: 200,
        msg: '获取成功',
        data
      })
    }
  }else{
    let data = await billModel.find().populate('After_sales_managementid').populate('goodsid').populate('groupsid')
    res.send({
      code: 200,
      msg: '获取成功',
      data
    })
  }
})




module.exports = router;
